import groovy.jmx.builder.modelmbean.CollectorHelper

class CollectorHelperTest extends GroovyTestCase {
    def dataGenerator

    void setUp() {
        dataGenerator = new NodeDataGenerator()
    }

    void testCollectParamInfo() {
        def info = CollectorHelper.collectParamInfo(dataGenerator.generateOpNodeData())
        assert info != null
        assert info.size() == 3
    }

    void testCollectParamInfo2() {
        def bean = new TestJavaBean()
        def info = CollectorHelper.collectParamInfo(bean.class.constructors[0])
        assert info != null
        assert info.size() == 1
    }

    void testGetAttrNodeData() {
        def nodeTree = dataGenerator.generateMBeanNodeData()
        def color = CollectorHelper.getAttrNodeData(nodeTree, nodeTree.object.metaClass.getMetaProperty("color"))
        assert color != null
        assert color.name.equals("color")
    }

    void testGetOpNodeData() {
        def nodeTree = dataGenerator.generateMBeanNodeData()
        assert nodeTree != null
        def method
        for (MetaMethod m in nodeTree.object.metaClass.methods) {
            if (m.name.equals("toss")) {
                method = m
                break
            }
        }
        def opNode = CollectorHelper.getOpNodeData(nodeTree, method)
        assert opNode != null

        for (MetaMethod m in nodeTree.object.metaClass.methods) {
            if (m.name.equals("stretch")) {
                method = m
                break
            }
        }
        opNode = CollectorHelper.getOpNodeData(nodeTree, method)
        assert opNode != null
    }
}